<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Driver_vehicle_schedule extends Admin_Controller {

	/** Begin: Config **/
	
	// Config all fields
	protected $fields =  array(
			'name'		=>	array(
								'text'	=>	'Tên',
								'type'	=>	'text',
								'list_view' => array(
									'is_show_link'	=>	true
								)
							),
			'driver_vehicle_id'		=>	array(
								'text'	=>	'Tài xế - Xe',
								'type'	=>	'select',
								'form_view' => array(
									'data_table'			=>	DRIVER_VEHICLE_TABLE,
									'condition'				=>	'',
									'parent_text'			=>	'name',
									'default_parent_text'	=>	'Chọn tài xế - xe'
								)
							),
			'schedule_id'	=>	array(
								'text'	=>	'Xe',
								'type'	=>	'select',
								'form_view' => array(
									'data_table'			=>	SCHEDULE_TABLE,
									'condition'				=>	'',
									'parent_text'			=>	'start_time',
									'default_parent_text'	=>	'Chọn lịch trình'
								)
							)
			);
	
	/*------------------------------------ Admin Control Panel ------------------------------------*/
	protected function after_save($obj_id){
		$obj = $this->model->getDetailManagement($obj_id);
		if(!empty($obj)){
			$name = '';
			$driver_vehicle = $this->model->get('*',DRIVER_VEHICLE_TABLE,"id = {$obj->driver_vehicle_id}",true);
			if(!empty($driver_vehicle)){
				$name .= $driver_vehicle['name'];
			}
			$schedule = $this->model->get('*',SCHEDULE_TABLE,"id = {$obj->schedule_id}",true);
			if(!empty($schedule)){
				$name .= ' - '.$schedule['start_time'];
			}
			if(!empty($name)){
				$data['name'] = $name;
				$this->model->update($this->table,$data,"id = {$obj_id}");
			}
		}
	}
	/*------------------------------------ End Admin Control Panel --------------------------------*/
	
	
	/*------------------------------------ FRONTEND ------------------------------------*/
	
	/*------------------------------------ End FRONTEND --------------------------------*/
}